package com.weixin.paleituo.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.R;
import com.weixin.paleituo.activity.GoodsStoreActivity;
import com.weixin.paleituo.activity.InvoiceDetailActivity;
import com.weixin.paleituo.activity.OrderDetailsActivity;
import com.weixin.paleituo.base.BaseOrderRecycleAdapter;
import com.weixin.paleituo.bean.GoodsListBean;
import com.weixin.paleituo.bean.StoreListBean;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.eventbus.CompleteOrderEvent;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.MyHorizontalScrollView;
import com.weixin.paleituo.view.TipsDialog;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Author yichao
 * Time  2018/4/7 17:51
 * Dest  完成订单
 */

public class ComplemtOrderRecycleAdapter extends BaseOrderRecycleAdapter {


    public ComplemtOrderRecycleAdapter(Context context, List<StoreListBean> storeListBeans) {
        super(context, storeListBeans);
    }

    @Override
    protected void setNoCustomCompleteData(NoCustomCompleteViewHolder noCustomCompleteViewHolder, final StoreListBean storeListBean, List<GoodsListBean> goodsList, final int position) {
        String storeName = storeListBean.getStoreName();
        if (!StringUtils.isEmpty(storeName) && storeName.equals("舒社")) {
            noCustomCompleteViewHolder.mIvIconItemOrderCompleteHead.setImageResource(R.mipmap.shushe_logo);
            noCustomCompleteViewHolder.mTvStoreNameItemOrderCompleteHead.setText("舒社");
            noCustomCompleteViewHolder.mIvMoreItemOrderHead.setVisibility(View.INVISIBLE);
        } else {
            noCustomCompleteViewHolder.mIvMoreItemOrderHead.setVisibility(View.VISIBLE);
            noCustomCompleteViewHolder.mIvIconItemOrderCompleteHead.setImageResource(R.mipmap.store_cart);
            noCustomCompleteViewHolder.mTvStoreNameItemOrderCompleteHead.setText(storeListBean.getStoreName());
            noCustomCompleteViewHolder.mLlStorerootItemOrderCompleteHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GoodsStoreActivity.startActivity(mContext,storeListBean.getStoreId());
                }
            });
        }

        HorizontalScrollViewGoodsItemAdapter horizontalScrollViewGoodsItemAdapter=new HorizontalScrollViewGoodsItemAdapter(mContext, (ArrayList<GoodsListBean>) goodsList);

        noCustomCompleteViewHolder.mIdHorizontalScrollViewItemNocustomAwaitfor.initDatas(horizontalScrollViewGoodsItemAdapter);

        noCustomCompleteViewHolder.mTvGoodsnumberNocustomComplete.setText("共" + storeListBean.getNum() + "件商品  ");
        noCustomCompleteViewHolder.mTvAwaitpayforNocustomComplete.setText("￥" + UIUtils.getMoney( storeListBean.getActualPrice()));
        noCustomCompleteViewHolder.mIdHorizontalScrollViewItemNocustomAwaitfor.setOnItemClickListener(new MyHorizontalScrollView.OnItemClickListener() {
            @Override
            public void onClick(View view, int pos) {
                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(), storeListBean.getDetailId() + "");
                mContext.startActivity(intent);
            }
        });
        noCustomCompleteViewHolder.mTvSurerecevingNoccustomComplete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               //查看发票
                mContext.startActivity(InvoiceDetailActivity.call2InvoiceDetailActivity(mContext, storeListBean.getId()));
            }
        });
        noCustomCompleteViewHolder.mIvDeleteItemOrderCompleteHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showGotGoodsDialog(position,"确定删除订单","取消","确定", Contans.DELETE_ORDER_TYPE);


            }
        });
        noCustomCompleteViewHolder.mLlNocustomRightLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(),null);
                mContext.startActivity(intent);
            }
        });
    }

    private TipsDialog mTipsDialog;
    /**
     * 弹窗
     * @param position
     * @param content
     * @param left
     * @param right
     */
    private void showGotGoodsDialog(final int position, final String content, String left , String right, final int type) {

        mTipsDialog = new TipsDialog.Builder(mContext)
                .setCancelClickListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        mTipsDialog.dismiss();
                    }
                })
                .setContentView(content)
                .setLeftButton(left, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mTipsDialog.dismiss();
                    }
                })
                .setRightButton(right, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mTipsDialog.dismiss();

                        EventBus.getDefault().post(new CompleteOrderEvent(position,type));


                    }
                })
                .build();

        mTipsDialog.show();
    }


    @Override
    protected void setCustomCompleteData(CustomCompleteViewHolder customCompleteViewHolder, final StoreListBean storeListBean, List<GoodsListBean> goodsList, final int position) {
        String storeName = storeListBean.getStoreName();
        if (!StringUtils.isEmpty(storeName) && storeName.equals("舒社")) {
            customCompleteViewHolder.mIvIconItemOrderCompleteHead.setImageResource(R.mipmap.shushe_logo);
            customCompleteViewHolder.mTvStoreNameItemOrderCompleteHead.setText("舒社");
            customCompleteViewHolder.mIvMoreItemOrderHead.setVisibility(View.INVISIBLE);
        } else {
            customCompleteViewHolder.mIvMoreItemOrderHead.setVisibility(View.VISIBLE);
            customCompleteViewHolder.mIvIconItemOrderCompleteHead.setImageResource(R.mipmap.store_cart);
            customCompleteViewHolder.mTvStoreNameItemOrderCompleteHead.setText(storeListBean.getStoreName());
            customCompleteViewHolder.mLlStorerootItemOrderCompleteHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GoodsStoreActivity.startActivity(mContext,storeListBean.getStoreId());
                }
            });
        }

        Glide.with(mContext).load(goodsList.get(0).getListUrl()).into(customCompleteViewHolder.mIvGoodsiconCustomForPricing);
        customCompleteViewHolder.mTvMessgeCustomForPricing.setText(storeListBean.getMsg() + "");
        customCompleteViewHolder.mTvGoodsnumberCustomComplete.setText("共" + storeListBean.getNum() + "件商品  ");
        customCompleteViewHolder.mTvAwaitpayforCustomComplete.setText("￥" + storeListBean.getActualPrice());
        customCompleteViewHolder.mTvSurerecevingCcustomComplete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              //
                mContext.startActivity(InvoiceDetailActivity.call2InvoiceDetailActivity(mContext, storeListBean.getId()));
            }
        });
        customCompleteViewHolder.mLlCustomconetRootLayoutOrderCustomConttent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(), storeListBean.getDetailId() + "");
                mContext.startActivity(intent);

            }
        });
        customCompleteViewHolder.mIvDeleteItemOrderCompleteHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                showGotGoodsDialog(position,"确定删除订单","取消","确定", Contans.DELETE_ORDER_TYPE);
            }
        });


    }




}
